package com.example.conventor;

import com.example.constant.UserStatus1;
import com.example.constant.UserStatus2;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;

/**
 * 反序列化程序
 */
public class UserStatusEnum2Deserializer extends JsonDeserializer<UserStatus2> {
    @Override
    public UserStatus2 deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
            throws IOException {
        final String source = jsonParser.getText();

        System.out.println("正在执行UserStatus的deserialize方法:"+source);
        int i = Integer.parseInt(source);
        UserStatus2[] values = UserStatus2.values();
        for (UserStatus2 value : values) {
            if (i==(value.getValue())) {
                System.out.println("已匹配到正确的UserStatus数据并返回:"+value);
                return value;
            }
        }
        throw new RuntimeException("无效枚举值");
    }
}

